using System;
using System.Collections;
using System.Text;

namespace BurbleLite
{
	/// <summary>
	/// Summary description for History.
	/// </summary>
	public class History
	{
		public Hashtable Buffers = new Hashtable();

		public string[] GetUsers()
		{
			ArrayList res = new ArrayList();
			foreach (string str in Buffers.Keys)
				res.Add(str);

			return (string[])res.ToArray(typeof(string));
		}
		public UserBuffer GetUserBuffer(string username)
		{
			return (UserBuffer)Buffers[username];
		}
		public string GetUserMessages(string username)
		{
			string[] res = new string[]{};
			if (((UserBuffer)Buffers[username]).Messages.Count > 0)
			{
				res = (string[])((UserBuffer)Buffers[username]).Messages.ToArray(typeof(string));
			}
			((UserBuffer)Buffers[username]).Messages.Clear();

			StringBuilder sb = new StringBuilder();
			foreach (string str in res)
			{
				sb.Append(str);
			}
			return sb.ToString();
		}

		public void AddMessageToAllBuffers(string text)
		{
			foreach (string key in Buffers.Keys)
			{
				((UserBuffer)Buffers[key]).Messages.Add(text);
			}
		}

		public void AddUserBuffer(string username)
		{
			if (Buffers.ContainsKey(username) == false)
				Buffers.Add(username, new UserBuffer(username));
		}
		
	}
}
